﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace WF.pages.system.ashx
{
    /// <summary>
    /// $codebehindclassname$ 的摘要描述
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class systems : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (System.Web.HttpContext.Current.Request["modeType"] != null)
            {
                if (System.Web.HttpContext.Current.Request["modeType"].ToString() == "xml")
                {
                    context.Response.ContentType = "application/xml";
                }
            }
            else
                context.Response.ContentType = "text/plain";
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            //context.Response.Write(QueryValue("SysName"));
            //QueryXmlDocu();
            string result = "";
            string p_MothodName = QueryValue("MothodName");
            result = GetPageData(p_MothodName, context);
            context.Response.Write(result);
        }
        private System.Xml.XmlDocument QueryXmlDocu()
        {
            System.Xml.XmlDocument xd2 = new System.Xml.XmlDocument();
            if (System.Web.HttpContext.Current.Request["modeType"] == "xml")
            {
                try
                {
                    System.Web.HttpContext.Current.Response.ContentType = "application/xml";
                    xd2.Load(System.Web.HttpContext.Current.Request.InputStream);
                    //返回xml格式
                    return xd2;
                }
                catch (Exception ex)
                {
                    System.Web.HttpContext.Current.Response.ContentType = "text/plain";
                    //返回文本格式
                    System.Web.HttpContext.Current.Response.Write(ex.Message);
                    System.Web.HttpContext.Current.Response.End();
                    return new System.Xml.XmlDocument();
                }

            }
            else
                return new System.Xml.XmlDocument();
        }
        BusWEB.WFInterface.Systems bws = new BusWEB.WFInterface.Systems();
        private string GetPageData(string p_MothedName, HttpContext context)
        {
            //根據方法名用於區分調用不同的類文件的公共入口

            switch (p_MothedName)
            {
                case "GetSystemMenu":
                    {
                        return bws.GetUserfolders(QueryValue("parefolderid"), QueryValue("foldernm"));
                    }
                case "GetSystemTopMenu":
                    {
                        return bws.GetUserfolders(QueryValue("parefolderid"), QueryValue("foldernm"));
                    }
            }
            return "";
        }
        private string QueryValue(string p_key)
        {
            if (System.Web.HttpContext.Current.Request.Params[p_key] != null)
                return System.Web.HttpContext.Current.Request.Params[p_key];
            else
                return "";
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
